package com.hevery.security.browser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author: zhy
 * @description: 实现UserDetailsService接口
 * @date: created on 2017/10/23
 * @modified by:
 */
@Component
public class MyUserDetailsService implements UserDetailsService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        logger.info("登录的用户名："+username);
        /**根据用户名查找用户信息*/
        /**根据查找到信息判断用于是否被冻结;实际上passwordEncoder.encode("123456")这个是在注册的时候做的;登录的时候应该就是拿出数据库中的值直接放在这里就可以了*/
        String password = passwordEncoder.encode("123456");
        logger.info("数据库密码是："+password);
        return new User(username,password, true,true,true,true,AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
//        return new User(username,"123456", AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));

    }
}
